package resource;

import java.io.FileReader;
import java.util.ArrayList;

import javax.xml.parsers.SAXParserFactory;

import launch.SimpleTest;

import org.xml.sax.InputSource;

import resource.handler.DialogHandler;

import dialog.DialogDeroulement;

public class DialogManager {
	private static ArrayList<DialogDeroulement> l_dial;
	
	/**
	 * Constructeur de gestionnaire de dialogue
	 * @param file
	 */
	public static void init(String file){
		l_dial = new ArrayList<DialogDeroulement>();
	    javax.xml.parsers.SAXParserFactory spf = SAXParserFactory.newInstance();
	    spf.setValidating(false);
	    javax.xml.parsers.SAXParser sp;
		try {
			sp = spf.newSAXParser();
		    org.xml.sax.InputSource input = new InputSource(new FileReader(file));
		    DialogHandler handler = new DialogHandler(l_dial);
		    sp.parse(input, handler);
		} catch (Exception e) {
			e.printStackTrace();
		};
	}
	
	public static void runDialog(String name){
		for(DialogDeroulement dd : l_dial){
			if(dd.getName().equals(name)){
				SimpleTest.changePlayerCommands(false);
				dd.choose(0);
			}
		}
	}
}
